
#include <bur/plctypes.h>

#ifdef _DEFAULT_INCLUDES
	#include <AsDefault.h>
#endif

void _INIT ProgramInit(void)
{

	DatObjInfo_0.enable = 1;
	DatObjInfo_0.pName = (UDINT)&"McAcpSys";
	DatObjInfo(&DatObjInfo_0);
	
	MO_ver("McAcpSys", 0, &VersionMcAcpSys);

	TempDTStruct.year	= VersionMcAcpSys.year;
	TempDTStruct.month	= VersionMcAcpSys.month;
	TempDTStruct.day	= VersionMcAcpSys.day;
	TempDTStruct.hour	= VersionMcAcpSys.hour;
	TempDTStruct.minute	= VersionMcAcpSys.minute;
	TempDTStruct.second	= VersionMcAcpSys.second;
	CreateDateMcAcpSys = DTStructure_TO_DT((UDINT) &TempDTStruct);
	
	brsstrcpy((UDINT)&gVersionMcAcpSys, (UDINT)&VersionMcAcpSys.version);
	dtoa(CreateDateMcAcpSys, (UDINT)&TempString);
	brsstrcat((UDINT)&gVersionMcAcpSys, (UDINT)&"(");
	brsstrcat((UDINT)&gVersionMcAcpSys, (UDINT)&TempString);
	brsstrcat((UDINT)&gVersionMcAcpSys, (UDINT)&")");


	DatObjInfo_1.enable = 1;
	DatObjInfo_1.pName = (UDINT)&"McAcpTrak";
	DatObjInfo(&DatObjInfo_1);
	
	MO_ver("McAcpTrak", 0, &VersionMcAcpTrak);

	TempDTStruct.year	= VersionMcAcpTrak.year;
	TempDTStruct.month	= VersionMcAcpTrak.month;
	TempDTStruct.day	= VersionMcAcpTrak.day;
	TempDTStruct.hour	= VersionMcAcpTrak.hour;
	TempDTStruct.minute	= VersionMcAcpTrak.minute;
	TempDTStruct.second	= VersionMcAcpTrak.second;
	CreateDateMcAcpTrak = DTStructure_TO_DT((UDINT) &TempDTStruct);
	
	brsstrcpy((UDINT)&gVersionMcAcpTrak, (UDINT)&VersionMcAcpTrak.version);
	dtoa(CreateDateMcAcpTrak, (UDINT)&TempString);
	brsstrcat((UDINT)&gVersionMcAcpTrak, (UDINT)&"(");
	brsstrcat((UDINT)&gVersionMcAcpTrak, (UDINT)&TempString);
	brsstrcat((UDINT)&gVersionMcAcpTrak, (UDINT)&")");

	
	
	
	// dummy use of retain variables - to ensure the value is retained during downloading other tasks
	DummyUse = (UDINT)&(gShuttleMove);
	DummyUse = (UDINT)&(gSegmentParIDText);
	DummyUse = (UDINT)&(gShuttleMeter);
	DummyUse = (UDINT)&(gShuttleMoveSelect);
	DummyUse = (UDINT)&(gCockpTracePar);
	DummyUse = (UDINT)&(gAutoCalibAMR);
	DummyUse = (UDINT)&(gSwDoorBypass);
	

	
	gIoPS080[0].CmdClearError = 0;
	
	gAiTemp11 = gAiTemp12 = gAiTemp13 = gAiTemp14 = gAiTemp15 = gAiTemp16 = 0;
	gAiTemp21 = gAiTemp22 = gAiTemp23 = gAiTemp24 = gAiTemp25 = gAiTemp26 = 0;
	gAiTemp31 = gAiTemp32 = gAiTemp33 = gAiTemp34 = gAiTemp35 = gAiTemp36 = 0;
	gAiTemp41 = gAiTemp42 = gAiTemp43 = gAiTemp44 = gAiTemp45 = gAiTemp46 = 0;
	gAiTemp51 = gAiTemp52 = gAiTemp53 = gAiTemp54 = gAiTemp55 = gAiTemp56 = 0;
	gAiTemp61 = gAiTemp62 = gAiTemp63 = gAiTemp64 = gAiTemp65 = gAiTemp66 = 0;
	gAiTemp71 = gAiTemp72 = gAiTemp73 = gAiTemp74 = gAiTemp75 = gAiTemp76 = 0;
	
//	brsstrcpy((UDINT)&IoAccReadDevice,		(UDINT)&"SL1.IF1.ST129.IF1.ST5");
	brsstrcpy((UDINT)&IoAccReadDevice,		(UDINT)&"SL1.IF1.ST129.IF1.ST12");
//	brsstrcpy((UDINT)&IoAccReadRegister,	(UDINT)&"129");
	brsstrcpy((UDINT)&IoAccReadRegister,	(UDINT)&"Temperature01");
	
//	brsstrcpy((UDINT)&IoAccWriteDevice,		(UDINT)&"SL1.IF1.ST129.IF1.ST5");
	brsstrcpy((UDINT)&IoAccWriteDevice,		(UDINT)&"SL1.IF1.ST129.IF1.ST12");
//	brsstrcpy((UDINT)&IoAccWriteRegister,	(UDINT)&"1029");
	brsstrcpy((UDINT)&IoAccWriteRegister,	(UDINT)&"ChopperOffset01");
	
}




void _CYCLIC ProgramCyclic(void)
{

	gIoPS080[0].Current = gIoPS080[1].Current + gIoPS080[2].Current + gIoPS080[3].Current + gIoPS080[4].Current + gIoPS080[5].Current + gIoPS080[6].Current;

	if(CmdAsIOAccRead)
	{
		AsIOAccRead_0.enable		= 1;
		AsIOAccRead_0.pDeviceName	= (UDINT)IoAccReadDevice;
		AsIOAccRead_0.pChannelName	= (UDINT)IoAccReadRegister;
		AsIOAccRead(&AsIOAccRead_0);
		if(AsIOAccRead_0.status != ERR_FUB_BUSY)
		{
			CmdAsIOAccRead = 0;
		}
	}
	
	if(CmdAsIOAccWrite)
	{
		AsIOAccWrite_0.enable		= 1;
		AsIOAccWrite_0.pDeviceName	= (UDINT)IoAccWriteDevice;
		AsIOAccWrite_0.pChannelName	= (UDINT)IoAccWriteRegister;
		AsIOAccWrite(&AsIOAccWrite_0);
		if(AsIOAccWrite_0.status != ERR_FUB_BUSY)
		{
			CmdAsIOAccWrite = 0;
		}
	}
	
}




void _EXIT ProgramExit(void)
{

}

